<template>
	<view class="detail">
		<view class="title">
			{{data.title}}
		</view>
		<view class="info">
			<view class="author">编辑：{{data.author}}</view>
			<view class="time">发布日期：{{data.posttime}}</view>
		</view>
		<view class="content">
			<rich-text :nodes="data.content"></rich-text>
		</view>
		<view class="description">
			声明:本站的内容均采集与腾讯新闻，如果侵权请联系管理员(513894357@qq.com)进行整改删除，本站进行了内容采集不代表本站及作者观点，若有侵犯请及时联系管理员谢谢您的支持。
		</view>
	</view>
</template>

<script>
	import { parseTime } from '../../utrls/tool.js';
	export default {
		data() {
			return {
				option:{},
				data:{},
			};
		},
		onLoad(e){
			this.option = e;
			this.getDetail();
		},
		methods:{
			getDetail(){
				uni.request({
					url:"https://ku.qingnian8.com/dataApi/news/detail.php",
					data: this.option,
					success: (res) => {
						res.data.posttime = parseTime(res.data.posttime)
						res.data.content = res.data.content.replace(/<img/gi,'<img style="max-width:100%"');
						this.data = res.data;
						this.saveHistory();
						uni.setNavigationBarTitle({
							title: this.data.title
						})
					}
				})
			},
			saveHistory(){
				let item = {
					id: this.data.id,
					classid: this.data.classid,
					picurl: this.data.picurl,
					title: this.data.title,
					looktime: parseTime(Date.now()) 
				}
				let historyArr = uni.getStorageSync("historyArr") || [];
				let index = historyArr.findIndex(i => {
					return i.id == this.data.id 
				})
				if(index >= 0) {
					historyArr.splice(index,1);
				}
				historyArr.unshift(item).splice(0,10);
				uni.setStorageSync("historyArr",historyArr);
			}
		}
	}
</script>

<style lang="scss">
.detail{
	padding: 30rpx;
	.title{
		font-size: 46rpx;
		color: #333;
	}
	.info{
		background-color: #F6F6F6;
		padding: 10rpx;
		font-size: 22rpx;
		color: #666;
		display: flex;
		justify-content: space-between;
		margin: 40rpx 0;
	}
	.content{
		padding-bottom: 50rpx;
		img{
			max-width: 100%;
		}
	}
	.description{
		background: #FEF0F0;
		font-size: 26rpx;
		padding: 20rpx;
		color: #F89898;
		line-height: 1.8em;
	}
}
</style>
